home *** CD-ROM | disk | FTP | other *** search
- Path: godel.une.edu.au!norm
- From: norm@godel.une.edu.au (Norman Gaywood)
- Newsgroups: comp.unix.osf.osf1,comp.lang.c
- Subject: Re: printf-problem
- Date: 22 Jan 1996 03:37:23 GMT
- Organization: University of New England, NSW, Australia
- Message-ID: <4dv0pj$nh2@grivel.une.edu.au>
- References: <4dj4g6$t9f@sunsystem5.informatik.tu-muenchen.de> <4dojc3$g2j@surz03fi.HRZ.Uni-Marburg.DE>
- NNTP-Posting-Host: godel.une.edu.au
- X-Newsreader: NN version 6.5.0 #15 (NOV)
-
- reeh@bunsen.HRZ.Uni-Marburg.DE (Achim Reeh) writes:
-
- >Henrik Wist (wist@lam.mw.tu-muenchen.de) wrote:
- >: Problem:
- >: long int zahl; /* which is e.g. 10000500001 */
- >: printf("%d\n",zahl); /* gives 1410565409, which is definitly wrong */
-
- >Solution:
- > printf("%ld\n",zahl); /* gives 10000500001 */
- > ^^^
- >%ld is the format specifier for long int output. long ints are 64 bit
- >under DEC Unix and DEC C. ints (format %d) have only 32 bit.
-
- OK, what about this one:
-
- -------------------------------Cut----------------------
- cat > sprintfbug.c
- #include <stdio.h>
-
- main()
- {
- static char buff[20] = "!!!!!";
- int width = 4;
- int lprecision = 0;
- double val = 10.0;
-
- sprintf( buff,"%*.*f", width, lprecision, val);
- printf( ":%s:\n", buff );
- }
- ^D
- % cc -o sprintfbug sprintfbug.c
- % sprintfbug
- : 10!:
- % uname -a
- OSF1 metz.une.edu.au V3.2 17 alpha
- -------------------------------Cut----------------------
-
- The output should be:
- : 10:
-
- I found this while trying to get the sc spreadsheet working correctly.
- This is not a problem in OSF 2.0
-
- --
- Norman Gaywood. Department of Mathematics, Statistics and Computing Science.
- University of New England, Armidale, NSW 2351, Australia.
- Internet: norm@godel.une.edu.au, phone: +61 67 732412, fax: +61 67 733312
-